package cn.gailvlun.gll.presentation.login.bean;

import android.support.annotation.NonNull;

import com.github.promeg.pinyinhelper.Pinyin;

import java.io.Serializable;



public class CountryCode implements Comparable<CountryCode>, Serializable {
    private String countryName;
    private String countryCode;

    public String getCountryName() {
        return countryName;
    }

    public void setCountryName(String countryName) {
        this.countryName = countryName;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public char getFirstLetter() {
        return Pinyin.toPinyin(countryName.charAt(0)).charAt(0);
    }

    public static CountryCode transform(String str) {
        String[] country = str.split(" ");
        CountryCode countryCode = new CountryCode();
        countryCode.setCountryName(country[0]);
        countryCode.setCountryCode(country[1]);
        return countryCode;
    }

    
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof CountryCode)) {
            return false;
        }
        return countryName.equals(((CountryCode) obj).getCountryName()) &&
                countryCode.equals(((CountryCode) obj).getCountryCode());
    }

    @Override
    public int compareTo(@NonNull CountryCode o) {
        char myFirstLetter = getFirstLetter();
        char otherFirstLetter = o.getFirstLetter();
        return myFirstLetter > otherFirstLetter ? 1 : (myFirstLetter == otherFirstLetter ? 0 : -1);
    }
}
